*** Stata 15 reproduction code for

*Mader, Matthias & Harald Schoen.
*What a difference an event can make: The European refugee crisis, party competition, and voters’ responses in Germany
*West European Politics


*** Figure A3-1: DK/RF responses to party position items
***********************************************************

*** Figure: Share of DK/RF responses to questions about party positions on immigration

	* CREATE DATASET FOR LINEPLOT

	use "DATA_Figure1.dta", clear
	
	gen month = .			
	replace month = 	1	if track ==	19
	replace month = 	5	if track ==	20
	replace month = 	9	if track ==	21
	replace month = 	11	if track ==	22
	replace month = 	14	if track ==	23
	replace month = 	17	if track ==	24
	replace month = 	20	if track ==	25
	replace month = 	23	if track ==	26
	replace month = 	26	if track ==	27
	replace month = 	30	if track ==	28
	replace month = 	33	if track ==	29
	replace month = 	36	if track ==	30
	replace month = 	38	if track ==	31
	replace month = 	42	if track ==	32
	replace month = 	44	if track ==	33
	replace month = 	48	if track ==	34
	replace month = 	51	if track ==	35
	replace month = 	54	if track ==	36
	replace month = 	57	if track ==	37


	/*
	tempname line
	postfile `line' monat mip_immi_M mip_immi_L mip_immi_U mip_labor_M mip_labor_L mip_labor_U using Graph.dta, replace
	*/
	tempname line
	postfile `line' month immi_cdu_M immi_cdu_L immi_cdu_U immi_csu_M immi_csu_L immi_csu_U immi_afd_M immi_afd_L immi_afd_U immi_spd_M immi_spd_L immi_spd_U ///
						  immi_gruene_M immi_gruene_L immi_gruene_U immi_linke_M immi_linke_L immi_linke_U using Graph1.dta, replace
	
	forvalues y = 1/60 {
	foreach var in immi_cdum immi_csum immi_afdm immi_spdm immi_gruenem immi_linkem {
	ci means `var' [aw = weight1] if month==`y'
	scalar `var'_M = r(mean)
	scalar `var'_L = r(lb)
	scalar `var'_U = r(ub)
	}
	scalar monat = `y'

	post `line' (monat) (immi_cdum_M) (immi_cdum_L) (immi_cdum_U) (immi_csum_M) (immi_csum_L) (immi_csum_U) (immi_afdm_M) (immi_afdm_L) (immi_afdm_U) (immi_spdm_M) (immi_spdm_L) (immi_spdm_U) ///
						(immi_gruenem_M) (immi_gruenem_L) (immi_gruenem_U)	(immi_linkem_M) (immi_linkem_L) (immi_linkem_U)	
	}
	postclose `line'


	* LINEPLOT

	use Graph1.dta, clear

	#delimit ;
	twoway rspike immi_cdu_L immi_cdu_U month, color(black) lwidth(thick) ||
		connected immi_cdu_M month, sort clpattern(dash) lwidth(thick) clcolor(black) mcolor(black)  msymbol(i) ||
		rspike immi_csu_L immi_csu_U month, color(ltblue) lwidth(thick) ||
		connected immi_csu_M month, sort clpattern(dash) lwidth(thick) clcolor(ltblue) mcolor(ltblue) msymbol(i)  ||
		rspike immi_afd_L immi_afd_U month, color(blue) lwidth(thick) ||
		connected immi_afd_M month, sort clpattern(dash) lwidth(thick) clcolor(blue) mcolor(blue)  msymbol(i) ||
		rspike immi_spd_L immi_spd_U month, color(red) lwidth(thick) ||
		connected immi_spd_M month, sort clpattern(dash) lwidth(thick) clcolor(red) mcolor(red)  msymbol(i) ||
		rspike immi_gruene_L immi_gruene_U month, color(green) lwidth(thick) ||
		connected immi_gruene_M month, sort clpattern(dash) lwidth(thick) clcolor(green) mcolor(green)  msymbol(i) ||
		rspike immi_linke_L immi_linke_U month, color(cranberry) lwidth(thick) ||
		connected immi_linke_M month, sort clpattern(dash) lwidth(thick) clcolor(cranberry) mcolor(cranberry)  msymbol(i)
		legend(off)
		name(missing_pp, replace)
		text(.76 5 "AfD", color(blue)  size(large)) text(.01 61 "CSU", color(ltblue) size(large)) text(.05 61 "CDU", color(black) size(large))
		text(.09 61 "SPD", color(red)  size(large)) text(.17 61 "Left", color(cranberry) size(large)) text(.13 62 "Greens", color(green) size(large))		
		xlabel(1 "1/13" 13 "1/14" 25 "1/15" 37 "1/16" 49 "1/17" 61 "1/18", angle(0) labsize(large))
		ylabel(0(.2)1, angle(0) nogrid  labsize(large))
		xtitle("")
		ytitle("Fraction", angle(90) size(large))
		graphregion(color(white))
		title("DK/RF responses to party position items", color(gs0) size(large))
		;
	#delimit cr	
